package com.xhs.main.controller.cwb;

import com.alibaba.fastjson.JSONObject;
import com.xhs.main.entity.rsb.RsbShowMoney;
import com.xhs.main.service.rsb.impl.RsbShowMoneyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * create by ljw on 2020/10/17
 *
 */
@RestController
public class EmployeeController {

    @Autowired
    RsbShowMoneyServiceImpl rsbShowMoneyService;

    //员工工资展示
    @RequestMapping("/showemployeemoney")
    public Map<String,Object> getEmployeeDate(Integer page,Integer limit){
        List<RsbShowMoney> allShowMoneyByLimit = rsbShowMoneyService.getAllShowMoneyByLimit((page - 1) * limit , limit);
        List<RsbShowMoney> rsbShowMonies = rsbShowMoneyService.selectAllShowMoney();
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","访问成功");
        map.put("count",rsbShowMonies.size());
        map.put("data",allShowMoneyByLimit);
        System.out.println(map);
        return map;
    }

    //条件查询
    @RequestMapping("/showemployeemoneybycondition")
    public Map<String,Object> getEmployeeMoneyByCondition(@RequestParam("condition") String condition, Integer page, Integer limit){
        //获取前端传递的json数据
        JSONObject object = JSONObject.parseObject(condition);
        String employeeID = (String) object.get("employeeID");
        String people = (String) object.get("people");
        List<RsbShowMoney> allShowMoneyByLimit = rsbShowMoneyService.getByCondition(employeeID,people,(page-1)*limit,limit);
        List<RsbShowMoney> rsbShowMonies = rsbShowMoneyService.selectAllShowMoney();
        Map<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","访问成功");
        map.put("count",rsbShowMonies.size());
        map.put("data",allShowMoneyByLimit);
        System.out.println(map);
        return map;
    }

}
